package com.carey.blog.framework.latke.action;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;


import com.carey.blog.framework.latke.service.LangPropsService;
import com.carey.blog.framework.latke.service.ServiceException;
import com.carey.blog.framework.latke.util.Locales;

/**
 * Do nothing action.
 * 
 */
public class DoNothingAction extends AbstractAction {

	/**
	 * Default serial version uid.
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Logger.
	 */
	private static final Logger LOGGER = Logger.getLogger(DoNothingAction.class
			.getName());
	/**
	 * Language service.
	 */
	private LangPropsService langPropsService = LangPropsService.getInstance();

	@Override
	protected Map<?, ?> doFreeMarkerAction(
			final freemarker.template.Template template,
			final HttpServletRequest request, final HttpServletResponse response)
			throws ActionException {
		LOGGER.finest("Do nothing action[FreeMarker action]");
		final Map<String, Object> ret = new HashMap<String, Object>();

		try {
			final Locale locale = Locales.getLocale(request);
			Locales.setLocale(request, locale);

			final Map<String, String> langs = langPropsService.getAll(locale);
			ret.putAll(langs);
		} catch (final ServiceException e) {
			LOGGER.log(Level.SEVERE, e.getMessage(), e);
			throw new ActionException("Language model fill error");
		}

		return ret;
	}

	@Override
	protected JSONObject doAjaxAction(final JSONObject data,
			final HttpServletRequest request, final HttpServletResponse response)
			throws ActionException {
		LOGGER.finest("Do nothing action[Ajax action]");
		return new JSONObject();
	}
}
